# 代码结果：   
    # Composite: Composite1 (Level 1)
    # Leaf: Leaf1 (Level 2)


from abc import ABC, abstractmethod

# 抽象组件类
class Component(ABC):
    def __init__(self, name: str):
        self.name = name

    @abstractmethod
    def add(self, component: 'Component') -> None:
        pass

    @abstractmethod
    def remove(self, component: 'Component') -> None:
        pass

    @abstractmethod
    def display(self, depth: int) -> None:
        pass

# 叶子组件类
class Leaf(Component):
    def __init__(self, name: str):
        super().__init__(name)

    def add(self, component: 'Component') -> None:
        pass  # 叶子组件不需要实现 add 方法

    def remove(self, component: 'Component') -> None:
        pass  # 叶子组件不需要实现 remove 方法

    def display(self, depth: int) -> None:
        print(f"Leaf: {self.name} (Level {depth})")

# 组合组件类
class Composite(Component):
    def __init__(self, name: str):
        super().__init__(name)
        self._children = []

    def add(self, component: Component) -> None:
        self._children.append(component)

    def remove(self, component: Component) -> None:
        self._children.remove(component)

    def display(self, depth: int) -> None:
        print(f"Composite: {self.name} (Level {depth})")
        for child in self._children:
            child.display(depth + 1)

# 客户端类
class Client:
    def __init__(self, component: Component):
        self.component = component

    def operation(self) -> None:
        self.component.display(1)

# 客户端使用示例
if __name__ == "__main__":
    leaf = Leaf("Leaf1")
    composite = Composite("Composite1")
    composite.add(leaf)
    
    client = Client(composite)
    client.operation()